﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework.Utils;
namespace CNVP.JShop.Web.Admin.Template
{
    public partial class FileEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 54)) return;//判断页面权限
            if (!IsPostBack)
            {
                var path = Request.QueryString["path"];
                var fileName = Request.QueryString["file"];
                if (path == null)
                {
                    hfCurentPath.Value = @"~/Template/Default/";
                }
                else
                {
                    hfCurentPath.Value = path.ToString();
                }
                if (fileName == null)
                {
                    Response.Redirect("Template.aspx?path=" + hfCurentPath.Value, true);
                }
                if (FileUtils.FileExists(Server.MapPath(hfCurentPath.Value + fileName)))
                {
                    txtFileContent.Text = FileUtils.ReadFile(Server.MapPath(hfCurentPath.Value + fileName));
                }
                hfCurentFile.Value = fileName;
            }
        }

        protected void btEdit_Click(object sender, EventArgs e)
        {
            FileUtils.SaveFile(txtFileContent.Text, Server.MapPath(hfCurentPath.Value + hfCurentFile.Value));
            MessageUtils.ShowRedirect("修改完成。","Template.aspx?path="+hfCurentPath.Value);
        }
    }
}